const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { webpack } = require("webpack");

module.exports = {
  entry: "./src/index.js",
  mode:'development',
  output: {
    // filename: "main.js",
    filename: 'main.[chunkhash:8].js', // 给打包后的文件添加hash值
    path: path.resolve(__dirname, "dist"),
    // libraryTarget: 'umd',
    sourceMapFilename: "[file].map",
    clean: true,
  },
  devtool: "source-map",
  plugins: [
    // new (webpack.SourceMapDevToolPlugin({})),
    new HtmlWebpackPlugin({
      filename: path.resolve(__dirname, "./dist/index.html"),
      template: "index.html",
    }),
  ],
  module: {
    rules: [
      {
        test: /\.txt$/,
        use: [path.resolve(__dirname, "test-loader.js")],
      },
      {
        test: /\.m?e?js$/,
        use: {
          loader: "babel-loader",           // 此处这个loader是调用babel用的
          options: {
            presets: ["@babel/preset-env","@babel/preset-react"], // babel本身也是一个平台，真正做代码转义的，还需要另外的babel插件
          },
        },
      },
    ],
  },
  devServer: {
    static: {
      directory: path.join(__dirname, 'public'),
    },
    // compress: true,
    port: 9000,
  },
};
